<%@ page pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><fmt:message key="user.common.title"/></title>
<script src="<c:url value='/scripts/common.js'/>"></script>  
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<link rel="stylesheet" type="text/css" media="all"	href="/sasis/styles/layout.css" />
<script>
	var aa = '<c:out value="${testf}"/>';
  	
 	if(null!=aa && ""!=aa) 
 	{
 		alert(aa);
 		document.location = './userList.html?action=userList';
 	}
</script> 	
<script type="text/javascript">
<!--
function killErrors() {
return true;
}
window.onerror = killErrors;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
<script src="<c:url value='/scripts/common.js'/>"></script>
<script src="<c:url value='/scripts/change_region.js'/>"></script>
</head>

<body leftmargin="0" topmargin="0">

<html:form action="/manage/userList.shtml?action=userList" styleId="userInfoBean">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td class="home-content-title">
    <img src="../images/home_ico_listTitle.gif" width="22" height="20" align="absmiddle">
      用户管理</td>
  </tr>
  
  <tr>
  <td>
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td>&nbsp;</td>
                      <td width="10%" class="black12">&nbsp;</td>
                      <td width="19%">&nbsp;</td>
                      <td width="8%">&nbsp;</td>
                      <td width="8%">&nbsp;</td>
                      <td width="14%">&nbsp;</td>
                      <td width="21%">&nbsp;</td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td width="3%">&nbsp;</td>
                      <td>&nbsp;</td> 
                      <td> 
                      	<table  width="450" border="0" cellspacing="0" cellpadding="0" id="normalSrch">
                      	<tr>
                      		<td><fmt:message key="dept.common.name"/>：</td>
							<td>
							 	<input type="text" name="deptName" id="selectedText" size="12"  class="home-table-inputbox" value="<c:out value='${userInfoBean.deptName}'/>"/>
							 	<input type="hidden" name="deptId" id="selectedId" size="12"/>
								<input name="Submit" type="button" class="home-inputBtn" onclick="MM_openBrWindow('../deptChoose.html','','width=200,height=400,status=yes')" value="<fmt:message key="manager.common.func.select"/>" /></td>
                      		 <td><p align="right" class="black12"><fmt:message key="user.common.enName"/>：</td>
		                     <td><html:text property="enName" size="10" styleClass="home-table-inputbox"/></td>
                      	</tr>
                      	</table>
                      </td>
                      <td >
                      	<table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                         <td width="42" align="left">
                          <table width="42" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td width="8" align="left">
                              	<input name="Submit11" type="button" class="home-inputBtn" value='<fmt:message key="button.search"/>' onclick="javascript:searchList()"/>&nbsp;
                              </td>
                            </tr>
                          </table>
                         </td>
                          <td width="10">&nbsp;</td>
                          <td>
                          	<table width="42" border="0" cellspacing="0" cellpadding="0">
                              <tr>
	                              <td width="8" align="left">
	                              	<input name="Submit12" type="button" class="home-inputBtn" value='<fmt:message key="button.reset"/>' onclick="resetForm()"/>&nbsp;
	                              </td>
                              </tr>
                          </table></td>
                        </tr>
                      </table></td> 
                     <td width="3%">&nbsp;</td>
                      <td width="15%"><table border="0" cellspacing="0" cellpadding="0">
                        <tr>
                             <td width="8" align="left">
                             	<input name="Submit13" type="button" class="home-inputBtn" value='<fmt:message key="common.button.superSrch"/>' onclick="changeSearchStatus()"/>&nbsp;
                             </td>
                        </tr>
                      </table></td>
                      <td width="3%">&nbsp;</td>
                      </tr>
                      <tr>
                      <td width="3%">&nbsp;</td>
                       <td>&nbsp;</td> 
            
                      <td > 
                      	<table  width="440" border="0" cellspacing="0" cellpadding="0" id="superSrch" style="display:none">
                      	<tr>
                      		<td><fmt:message key="user.common.msisdn"/>：</td>
							<td>&nbsp;
							<html:text property="msisdn" size="12" maxlength="12" styleClass="home-table-inputbox" style="margin-left: 1px;"/> 	
							</td>
                      		 <td width=68 class="black12"><p style="text-align: right"><fmt:message key="user.common.cnName"/>：</td>
		                     <td><html:text property="cnName" size="10" styleClass="home-table-inputbox" style="margin-left: 1px;"/></td>
                      	</tr>
                      	<tr>
                      		<td><fmt:message key="manager.common.func.isUsable"/>：</td>
							<td width="200" class="black12">&nbsp;
							<html:radio property="isUsable" value="0" />
									是
                            <html:radio property="isUsable" value="1" />
									否	
							</td>
                      		 <td>&nbsp; </td>
		                     <td>&nbsp; </td>
                      	</tr>
                      	</table>
                     
                      </td>
                      <td >
                      	<table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                         <td width="42" align="left">
                          &nbsp; 
                         </td>
                          <td width="10">&nbsp;</td>
                          <td>&nbsp; </td>
                        </tr>
                      </table></td> 
                     <td width="3%">&nbsp;</td>
                      <td width="15%">&nbsp; </td>
                      <td width="3%">&nbsp;</td>
                    </tr>
                       </table>
                      </td>
                    </tr>
  <tr> 
    <td valign="top"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td class="home-table-topline"> </td>
        </tr>
        <tr> 
          <td class="home-table-leftline"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                 <table width="100%" border="0" cellspacing="0" cellpadding="0">
                 <tr>
                 <td  class="home-table-tool-content02">
                 	<input name="Submit21" type="button" class="home-inputBtn" value='选择' onclick="selectedCheck()"/>&nbsp;
          		</td>
				<td  class="home-table-tool-content02"><sasis:page items="${userList}"/></td>
				</tr>
				</table>
              </tr>
              <tr> 
                <td align="center" valign="top" class="home-table-leftline">
					<table width="100%" border="0" cellpadding="2" cellspacing="0" class="list_bordercolor">
					  <tr>
                      <td width="4%" height="26" class="home-list-title">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='selectAll'  
		               onclick='checkAll(this.checked);'/></td>
                      <td width="5%" class="home-list-title"><fmt:message key="messageLogForm.sort"/></td>
                      <td width="15%" class="home-list-title"><fmt:message key="user.common.department"/></td>
                      <td width="21%" class="home-list-title"><fmt:message key="user.common.enName"/></td>
                      <td class="home-list-title"><fmt:message key="user.common.cnName"/></td>
                      <td  width="8%" class="home-list-title"><fmt:message key="user.common.isUsable"/></td>
                     <!--  
                     <p:allow pid="6324"> 
                      <td width="6%" class="home-list-title"> <fmt:message key="provisionForm.view" /></td>
                     </p:allow>  -->
                    </tr>
                    <c:forEach var="results" items="${userList}"  varStatus="status">
                    <tr>
                      <td height="26" class="home-list-content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="id"  value="<c:out value='${results.id}'/>$<c:if test="${null==results.cnName}"><c:out value='${results.enName}'/></c:if><c:if test="${null!=results.cnName}"><c:out value='${results.cnName}'/></c:if>"/></td>
                      <td class="home-list-content">&nbsp;<c:out value="${status.count}"/></td>
                      <td class="home-list-content">&nbsp;<c:out value="${results.deptName}"/></td>
                      <td class="home-list-content">&nbsp;<c:out value="${results.enName}"/></td>
                      <td align="center" class="home-list-content">&nbsp;<c:out value="${results.cnName}"/></td>
                      <td align="center" class="home-list-content">&nbsp;
                      	<c:choose>
					 		<c:when test="${results.isUsable == 0}">
					 			<fmt:message key="runtimepatternForm.isnotice.1"/>
					 		</c:when>
					 		<c:otherwise>  
					 			<fmt:message key="runtimepatternForm.isnotice.0"/>
					        	
					        </c:otherwise>
				        </c:choose>	
                      </td>
                      <!--
                     <td align="center" class="home-list-content">
                      <p:allow pid="6324">
	                     <img src="../images/view.gif" width="14" height="14" 
						 onclick="javascript:edit('<c:out value="${results.enName}"/>','view')"
							alt="<fmt:message key="provisionForm.view" />" style="cursor:hand">
						</p:allow>
					</td>
					  -->  
                    </tr>
                    </c:forEach>
                    <tr>
                    <td width="2%">&nbsp;</td>
                    <td width="20%">&nbsp;</td>
                    <td width="17%">&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                     
                    <td> 
						 <select name="userselected" id="userselected" multiple="multiple"  style="width:15em;height: 100px;">
                    	</select>
				 </td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td> 
                    <td>&nbsp;<input type="button" class="home-inputBtn" value="确定" onclick="inputDatas()"/>&nbsp;<input type="button" class="home-inputBtn" value="删除" onclick="removeItems(document.getElementById('userselected'))"/></td>
                   
                  </tr>
                    </table>
                </td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td height="12"> <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td class="home-table-bottom-left">&nbsp;</td>
                <td class="home-table-bottom-bg">&nbsp;</td>
                <td class="home-table-bottom-right">&nbsp;</td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td height="10">&nbsp;</td>
  </tr>
</table>
<html:hidden property="aryId"/> 
<html:hidden property="seledId"/> 
<html:hidden property="handle"/> 
<input type="hidden" name="selectedUser" id="selectedUser" value="<c:out value="${param.selectedUser}"/>"/> 
<input type="hidden" name="selectedUserName" id="selectedUserName" value="<c:out value="${param.selectedUserName}"/>"/>
</html:form>

<script>  
		var oldids;
		var oldnames;

		var oldusername = window.opener.document.getElementById("username").value;
		var olduserid = window.opener.document.getElementById("userid").value;
		
		var newUsers = "<c:out value="${param.selectedUser}"/>";
		var newUserNames = "<c:out value="${param.selectedUserName}"/>";
		
		var userselected = document.getElementById("userselected");	
		 
		if(""!=newUsers && -1!=newUsers.indexOf(",")){	   

			 oldids = newUsers.split(",");
			 oldnames = newUserNames.split(","); 
			
			 
		}else{
			 oldids = olduserid.split(",");
			 oldnames = oldusername.split(",");
			 
		}
		
		 
		for(var i=0;i<oldids.length;i++){ 		 
				userselected.options.add(new Option(oldnames[i],oldids[i]));

		}
		
	
 
	//选择用户列表	
	function selectedCheck(){ 
		var nameary = submitData(); 
		var useridary = submitData1();
		var selUserName = document.getElementById("selectedUserName");
		var selectedUser = document.getElementById("selectedUser");
		
		var ids = new Array();
		var names = new Array();
		
		if(nameary.length>0){	  
            
			for(var i=0;i<useridary.length;i++){
			    //alert(checkOption(userselected,useridary[i]));
				if(checkOption(userselected,useridary[i])== true){
				    //alert("firstone:"+userselected.options[0]);
				    var firstone="";
				    if(userselected.options[0]!=null)
					   firstone = userselected.options[0].value;
					if(""==firstone){
						userselected.options.remove(0);
					}
					//alert("go_1::"+nameary[i]+"::"+useridary[i]);
					userselected.options.add(new Option(nameary[i],useridary[i]));
							 
				}
			} 
			
			//获取列表中的数据
			var options = userselected.options;
			for(var i=0;i<options.length;i++){
				ids.push(options[i].value);			 
				names.push(options[i].text);	
			}		
			
			selectedUser.value = ids;
			selUserName.value = names;
			
			ids.removeAll();
			names.removeAll();
			
		}else alert("请选择记录!");
		 
 	}
 
 
 function removeItems(ope){
	var ids = new Array();
	var names = new Array();
		 
	 var opeLen = ope.options.length;

	 if(0==opeLen || ''==ope.options[0].value){
	 	 alert("请选择删除!");
	 	 return;
	 }
	 	 
			 for(var i = opeLen-1; i >= 0; --i){ 
			 	if( ope.options(i).selected){
					 ope.options.remove(i);
				} 
				 
			 }

			//获取列表中的数据
			var options = userselected.options;
			for(var i=0;i<options.length;i++){
				ids.push(options[i].value);			 
				names.push(options[i].text);	
			}		
			
			selectedUser.value = ids;
			selUserName.value = names;
			ids.removeAll();
			names.removeAll();			 
}

	//返回选择用户列表
	function inputDatas(){
		var options = userselected.options;
		var ids = new Array();
		var names = new Array();
		for(var i=0;i<options.length;i++){
			ids.push(options[i].value);
			names.push(options[i].text);
		}

		window.opener.document.getElementById("username").value = names;
		 
		window.opener.document.getElementById("userid").value = ids;
		
		//ids.removeAll();
		//names.removeAll();
		
		window.close();
	}

	function submitData(){
		var chk = document.forms[0].id;
		var len = chk.length; 
		var ary = new Array();
		
		
		if(len>1){
			for(var i=0;i<len;i++){
				if(chk[i].checked){

					var intpos = chk[i].value.indexOf("$");
					var strlen = chk[i].value.length;

					ary.push(chk[i].value.substr(intpos+1));

					
				}
			
			}
		}else ary.push(chk.value);
		return ary;
	} 
   
   	function submitData1(){
   	
		var chk = document.forms[0].id;
		var len = chk.length; 
		var ary1 = new Array(); 
		if(len>1){
			for(var i=0;i<len;i++){
				if(chk[i].checked){

					var intpos = chk[i].value.indexOf("$");
					var strlen = chk[i].value.length;
					var chkVal = chk[i].value.substr(0,intpos);
					
					ary1.push(chkVal);
					
				}
			
			}
		}else ary1.push(chk.value);
		
	 
		return ary1;
	} 
	
	function selected(_form,_url,ary,userId){
	 
		//_form.seledId.value = ary; 
		//formSubmit(_form,_url); 
		MM_openBrWindow(_url+'&userId='+userId+'&seledId='+ary,'','width=500,height=280');
 	}
 	
 	function shSearch(eltName){
	 
	var elt = document.getElementById(eltName);

	if(elt.style.display=="none"){ 
		elt.style.display = "";
	}else elt.style.display = "none";

	} 
	
	function shSearch(source,target){
	 
	var sourceElt = document.getElementById(source);
	var targetElt = document.getElementById(target);
	var handle = document.forms[0].handle.value;
 	if(handle=="")handle = "source";
		if(handle=="source"){  
			document.forms[0].handle.value="target";
			document.forms[0].submit();
		}else if(handle=="target"){  
			document.forms[0].handle.value="source";
			document.forms[0].submit();
		}else if(handle==""){
			document.forms[0].handle.value="source";
			document.forms[0].submit();
		}
		
	} 
	
	function checkAll(status){
               //alert(status);
               for (var i=0;i < document.forms[0].elements.length; i++){
				var e = document.forms[0].elements[i];
				//alert(e.name);
				if (e.name=="id")
					document.forms[0].elements[i].checked=status;
			}
			
		}
		
 	function searchList(){ 
	 	var e = document.getElementById('superSrch'); 
		var type = document.forms[0].handle.value;
		var param1 = "";
		if(""!=type){
			param1 = "&srchType="+type;
		}
 		document.forms[0].action="./userList.shtml?action=userList&target=search&toChoose=true"+param1;
 		document.forms[0].submit(); 
 	
 	}
 	
 	function showType(){
		var e = document.getElementById('superSrch'); 
		var type = <%=request.getParameter("srchType")%>;
		if(type==0){
			e.style.display = '';
		}else e.style.display = 'none';
 	}
 	//auto search 
 	showType();
 	
 	function resetForm(){
        userInfoBean.reset();
    }
    function changeSearchStatus(){
		var elt = document.getElementById('superSrch');

		if(elt.style.display=="none"){ 
			elt.style.display = "";
			document.forms[0].handle.value=0;
		}else {
			elt.style.display = "none";
			document.forms[0].handle.value=1;			
		}	
	}
	


</script>
</body>
</html>
